<?php 
/* Template name: Portfolio */ 
?>


<?php get_header(); ?>
 <?php
				$page_name = trim( wp_title( '', false ) );
				$page = get_page_by_title( $page_name );
			?>
<div class="page-bg" style="background-image:url(<?php echo get_post_meta( $page->ID, 'page_subtitle', true ); ?>)"><p><?php echo trim( wp_title( '', false ) ); ?></p></div>
   <!-- Breadcrumbs -->    
	<div class="container">
    	<div class="row">
        	<div class="span12">
            	<div class="page-header">
                 <?php while (have_posts()) : the_post(); ?>
			<?php the_content(); ?><?php endwhile; ?>
        		</div>
            </div>
         </div>
               
                <!--FILTERS-->
  <div class="clearfix"> 
          <div class="row">
            <div class="span12">
            <ul class="unstyled" id="themeFilterableNav">
				 <li class="filter-tab">FILTER</li>
				 <?php $pf_terms = get_categories( 'type=portfolio&taxonomy=department' ); ?>
                 <li class="active-tag"><a data-filter="*" href="#"><?php echo __( 'all', 'themeText' ); ?></a></li>
                  
                    <?php foreach( $pf_terms as $pf_term ) : ?>
                    <li><a href="#" data-filter=".<?php echo $pf_term->slug; ?>"><?php echo $pf_term->name; ?></a>
</li>
                    <?php endforeach; ?>
                   
                </ul></div></div>
        <!-- end FILTERS -->

                <!-- PORTFOLIO -->
              <div class="row">
            	<div class="span12">
                	<div id="portfolio" class="row">
				<?php
				if ( have_posts() ) :
				
					$args = array( 'post_type' => 'portfolio', 'posts_per_page' => -1 );
					$loop = new WP_Query( $args );
					
					while ( $loop->have_posts() ) : $loop->the_post();
						
						$terms = get_the_terms( $post->ID, 'department' );
						$on_draught = '';
						
					if ( $terms && ! is_wp_error( $terms ) ) :
						
						$draught_links = array();

						foreach ( $terms as $term )
						{
							$draught_links[] = $term->slug;
						}
				
						$on_draught = join( " ", $draught_links );
						
					endif;
				?>
					<div class="span4 block <?php echo $on_draught; ?>">
                    <div class="block2">
						
							<?php 
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); 
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
if ($image) : ?>

    <a href="<?php the_permalink(); ?>"><img src="<?php echo $image[0]; ?>" /></a>
<?php endif; ?> 
							<section class="overlay">
                       <a style="text-decoration:none" href="<?php the_permalink() ?>"> <div class="morelink"><?php the_title(); ?></div></a></section>
                            
                            </div>
                            
                        </div>	
				<?php
					endwhile;
				endif;
				wp_reset_query();
				?>
</div>
                </div>
            </div>
            <!--/Latest-works -->
        </div>
        <!-- /Box1 -->

</div>
<script type="text/javascript" charset="utf-8">

jQuery.noConflict()(function($){
 var $container = $('#portfolio');
	$container.imagesLoaded( function(){
		$container.isotope({
			itemSelector : '.block',
			layoutMode : 'fitRows'
		});	
	});
		
		// filter items when filter link is clicked
		$('#themeFilterableNav a').click(function(){
		  var selector = $(this).attr('data-filter');
		  $container.isotope({ filter: selector });
		  $(this).parent().addClass('active-tag').siblings().removeClass('active-tag');
		  return false;
		});
});
</script>
   <?php get_footer(); ?>